//
// Created by webturing on 2024/1/1.
//
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int maxn = 100 + 50;
const int maxm = maxn * maxn;


int dis[maxn][maxn];
int n, m;
int ind[maxn];
int path[maxn], book[maxn];

bool Topsort() {
    queue<int> Q;
    int j = 0;
    do {
        for (int i = 0; i < n; i++) {
            if (ind[i] == 0 && book[i] == 0) {
                Q.push(i);
                book[i] = 1;
            }
        }
        if (Q.empty() && j < n)
            return false;
        int h = Q.front();
        path[j++] = h;
        Q.pop();
        for (int i = 0; i < n; i++) {
            if (dis[h][i] > 0) {
                dis[h][i] = 0;
                --ind[i];
                if (ind[i] == 0 && book[i] == 0) {
                    Q.push(i);
                    book[i] = 1;
                }
            }
        }
        if (j == n)return true;
    } while (Q.size());

    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ifstream fin("N.in");
    if (fin.good()) cin.rdbuf(fin.rdbuf());

    int T;
    cin >> T;
    while (T--) {
        map<string, string> M;
        set<string> S;
        cin >> m;
        for (int i = 0; i < m; i++) {
            string s1, s2;
            cin >> s1 >> s2;
            M[s1] = s2;
            S.insert(s1);
            S.insert(s2);
        }
        n = S.size();
        vector<string> words;
        for (auto w:S)words.push_back(w);
        copy(words.begin(), words.end(), ostream_iterator<string>(cerr, " "));
        cerr << endl;
        memset(dis, 0, sizeof(dis));
        memset(ind, 0, sizeof(ind));
        memset(book, 0, sizeof(book));
        for (auto p:M) {
            int i = find(words.begin(), words.end(), p.first) - words.begin();
            int j = find(words.begin(), words.end(), p.second) - words.begin();
            dis[i][j] = 1;
            ind[j]++;
        }

        if (Topsort()) {
            cout << "Passed" << endl;
        } else {
            cout << "Failed" << endl;
        }
    }

    return 0;
}
